package com.maxd.respository.admin;

import com.maxd.model.AdminInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface AdminRepository extends Repository<AdminInfo, Long> {

    @Query(value = "from AdminInfo s where s.phone=:phone")
    AdminInfo login(@Param("phone") String phone);


    @Query(value = "select * from admin_info a where admin_type=1 ",
            countQuery = "select count(*) from admin_info a where admin_type=1 ",nativeQuery = true)
    Page<AdminInfo> selectAdminInfoList(Pageable pageable);

    @Query(value = "select * from admin_info a where a.id=:id", nativeQuery = true)
    AdminInfo selectAdminInfoDetails(@Param("id") Long id);


    @Modifying
    @Query(value = "update AdminInfo s set s.pwd=:pwd where s.phone=:phone")
    Integer updatePwd(@Param("pwd") String pwd, @Param("phone") String phone);

}